Skip to content

Conversation

@innocenzi
Copy link
Member

@innocenzi innocenzi commented Jun 28, 2025

What

This pull request introduces a new tempest/process component, wrapping symfony/process. It is heavily inspired by Laravel's own process wrapper (conceptually, and some testing code as well).

The existing ShellExecutor in tempest/core has also been replaced with the introduced ProcessExecutor.

Usage

$executor = $this->container->get(ProcessExecutor::class);

// run a single process
$executor->run('echo "hello world"');

// wait for a process
$process = $executor->start('echo "hello world"');
$process->wait();

// multiple processes
[$first, $second] = $executor->concurrently([
  'echo "hello"',
  'echo "world"',
]);


$pool = $executor->pool([
  'echo "hello"',
  'echo "world"',
]);

$pool->run();

Testing

By default, executing processes is completely disabled during tests. This means developers will have to explicitly call registerProcessResult or allowRunningActualProcesses.

This is so that actual processes that could cause issues in local environments would not be executed by default. Developers would get failures in their tests until they explicitly mock processes with registerProcessResult, or specifically allow processes to actually run.

// fake a process result
$this->process->registerProcessResult('echo *', 'hello');

// allow processes to be actually executed, this is opt-in!
$this->process->allowRunningActualProcesses('echo *', 'hello');

// prevent processes from being actually executed, needs `registerProcessResult` calls after
$this->process->preventRunningActualProcesses();

// assertions
$this->process->assertCommandRan('echo *');
$this->process->assertCommandDidNotRun('echo *');
$this->process->assertRan(fn (PendingProcess $process, ProcessResult $result) => /* .. */);

@innocenzi innocenzi marked this pull request as ready for review June 28, 2025 14:53
@innocenzi innocenzi requested a review from brendt July 3, 2025 11:49
@innocenzi innocenzi force-pushed the feat/process branch 2 times, most recently from 6292e80 to b0ac458 Compare August 14, 2025 00:13
@innocenzi innocenzi changed the base branch from main to 2.x August 14, 2025 00:13
@innocenzi innocenzi merged commit 70bc5f8 into tempestphp:2.x Aug 14, 2025
77 checks passed
@innocenzi innocenzi deleted the feat/process branch August 14, 2025 15:57
Bapawe pushed a commit to Bapawe/tempest-framework that referenced this pull request Aug 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants